package top.ezzz.chats.config;

import lombok.extern.slf4j.Slf4j;
import org.noear.socketd.transport.core.Listener;
import org.noear.socketd.transport.core.Message;
import org.noear.socketd.transport.core.Session;
import org.noear.solon.annotation.Component;

import java.io.IOException;


@Slf4j
@Component
public class SocketDListener implements Listener {

    @Override
    public void onOpen(Session session) throws IOException {
        log.info(session.sessionId());
    }

    @Override
    public void onMessage(Session session, Message message) throws IOException {
        log.info(session.sessionId() + " = " + message.dataAsString());
        session.send("chat", message);
    }

    @Override
    public void onClose(Session session) {
        log.info(session.sessionId());
    }

    @Override
    public void onError(Session session, Throwable error) {
        log.info(session.sessionId());
    }
}
